package com.example.controller;

import com.example.service.NlpService;
import com.example.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/search")
public class SearchController {

    private final SearchService searchService;
    private final NlpService nlpService;

    public SearchController(SearchService searchService, NlpService nlpService) {
        this.searchService = searchService;
        this.nlpService = nlpService;
    }


    @GetMapping("/related")
    public List<String> getRelatedSearchTerms(@RequestParam String searchTerm, @RequestParam Long userId) throws Exception {

        // 保存搜索历史，现在考虑用户ID
        searchService.saveSearchHistory(userId, searchTerm);

        // 提取关键词
        List<String> keywords = nlpService.extractKeywords(searchTerm);

        // 获取相关搜索建议
        return searchService.getRelatedSearchTerms(keywords);
    }
}

